package com.xiaoyu.client.adapter.nearby;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;

import com.xiaoyu.client.R;
import com.xiaoyu.client.model.nearby.ShopTagParam;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShopTagAdapter extends BaseAdapter {
    private Context mContext;
    private List<ShopTagParam> mList = new ArrayList<>();
    private Map<String,String> mSelectList = new HashMap<>();

    public ShopTagAdapter(Context mContext, List<ShopTagParam> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public ShopTagParam getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    class ViewHolder{
        CheckBox mCheckBox;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_shop_type,parent,false);
            holder = new ViewHolder();
            holder.mCheckBox = convertView.findViewById(R.id.item_shop_type_choose_check);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.mCheckBox.setText(getItem(position).getTagName());
        if (mSelectList.containsKey(getItem(position).getTagId())){
            Log.i("xiaokai",getItem(position).getTagName()+"  check = "+true);
            holder.mCheckBox.setChecked(true);
        }else {
            holder.mCheckBox.setChecked(false);
            Log.i("xiaokai",getItem(position).getTagName()+"  check = "+false);
        }
        return convertView;
    }

    public void updateList(List<ShopTagParam> mList) {
        this.mList = mList;
        this.notifyDataSetChanged();
    }

    public void setSelectList(Map<String,String> mSelectList) {
        this.mSelectList = mSelectList;
        this.notifyDataSetChanged();
    }
}
